﻿using System;
using SpecialEffects;
using Microsoft.Xna.Framework;
using GlobalGameClasses;
using DrawableObjects.Actors.Aircrafts;

namespace DrawableObjects.Actors.Projectiles
{
    public class Missile : Projectile
    {
        /// <summary>
        /// this class creates the different level of weapons of the weaponsystem "missile"
        /// it also creates the enemy weapon
        /// </summary>
        private BasicFireAndSmoke smokeTrail
        {
            get;
            set;
        }


        private Missile(float speed, int baseDamage, string strTextureModel, Matrix worldMatrix, float scaleFactor, BasicFireAndSmoke smokeTrail, float boundingFactor, string explosionSound)
            : base(speed, baseDamage, strTextureModel, worldMatrix, scaleFactor, boundingFactor, explosionSound)
        {
            this.smokeTrail = smokeTrail;
            this.strTextureModel = strTextureModel;
        }

        public static Missile GET_MISSILE_LEVEL1()
        {
            return new Missile(1.3f, 30, "missile_player1",  Matrix.CreateWorld(new Vector3(0, GlobalGameValues.GAMEFIELD_HEIGHT, 0), Vector3.Backward, Vector3.Up), 0.15f, BasicFireAndSmoke.CreateSmokeTrail_Missile(), 1, "missileExplosion");
        }

        public static Missile GET_MISSILE_LEVEL2()
        {
            return new Missile(1.3f, 45, "missile_player2", Matrix.CreateWorld(new Vector3(0, GlobalGameValues.GAMEFIELD_HEIGHT, 0), Vector3.Backward, Vector3.Up), 0.5f, BasicFireAndSmoke.CreateSmokeTrail_Missile(), 1, "missileExplosion");
        }

        public static Missile GET_MISSILE_LEVEL3()
        {
            return new Missile(1.3f, 60, "missile_player2", Matrix.CreateWorld(new Vector3(0, GlobalGameValues.GAMEFIELD_HEIGHT, 0), Vector3.Backward, Vector3.Up), 0.6f, BasicFireAndSmoke.CreateSmokeTrail_Missile(), 1, "missileExplosion");
        }

        public static Missile GET_MISSILE_ENEMY()
        {
            return new Missile(0.7f, 9, "missile_player2", Matrix.CreateWorld(new Vector3(0, GlobalGameValues.GAMEFIELD_HEIGHT, 0), Vector3.Backward, Vector3.Up), 0.6f, BasicFireAndSmoke.CreateSmokeTrail_Missile(), 1, "missileExplosion");
        }

        public override void collide(Actor actor2)
        {
            base.collide(actor2);
            if (actor2.owner != this.owner && actor2 is Aircraft)
            {
                world.addSpecialEffect(BasicExplosion.CreateSmokeExpl_Weapon(worldMatrix.Translation, Vector3.Zero, (float)GlobalGameValues.Values.gameTime.TotalGameTime.TotalMilliseconds));
                world.addSpecialEffect(BasicExplosion.CreateExpl_Missile(worldMatrix.Translation, Vector3.Zero, (float)GlobalGameValues.Values.gameTime.TotalGameTime.TotalMilliseconds));
            }
        }

        public override Projectile Clone(Vector2 position, Vector2 direction)
        {
            this.direction = direction;
            Matrix newMatrix = this.worldMatrix;
            newMatrix.M41 = position.X;
            newMatrix.M43 = position.Y;
            Missile cloned = new Missile(this.speed, this.baseDamage, this.strTextureModel, newMatrix, this.scaleFactor, BasicFireAndSmoke.CreateSmokeTrail_Missile(), this.boundingSphereFactor, this.explosionSound);
            cloned.direction = direction;
            cloned.standardRotation = this.standardRotation;
            cloned.smokeTrail.SetPosition(cloned.worldMatrix.Translation);
            cloned.smokeTrail.SetDirection(-(new Vector3(cloned.direction.X, 0, cloned.direction.Y)));

            return cloned;
        }

        public override void Update()
        {
            base.Update();
            smokeTrail.SetPosition(worldMatrix.Translation);
            smokeTrail.SetDirection(-(new Vector3(direction.X, 0, direction.Y)));
            smokeTrail.Update();
        }

        public override void Initialize()
        {
            world.addSpecialEffect(smokeTrail);
            base.Initialize();
        }
    }
}

